var Action = require("../apiaction");
var DataProxy = require("data-proxy");

exports.shapanRouter = function(router){



    //导入人员信息
    router.get('/shapan/activity/importUser',function(req,res){

        var  activity_mid=req.param('activity_mid');

        res.render('shapan/01activity/importUser',{
            layout:'keb2/layout-keb',
            active:'importUser',
            jscript:'',
            activity_mid:activity_mid
        })
    });

    //导入市场需求
    router.get('/shapan/activity/importMarket',function(req,res){

        var  activity_mid=req.param('activity_mid');
        //console.log('yudan',activity_mid);
        res.render('shapan/01activity/importMarket',{
            layout:'keb2/layout-keb',
            active:'importMarket',
            jscript:'',
            activity_mid:activity_mid
        })
    });

    //组建团队
    router.get('/shapan/group/newcompany',function(req,res){
        var  activity_mid=req.param('activity_mid');
        var param={};
        param.activity_mid=activity_mid;
        Action.send(req,res,'/Group/groupNames',param,'GET',function(res,data){
            var data = JSON.parse(data).data;

        res.render('shapan/02group/newCompany',{
            layout:'keb2/layout-keb',
            active:'newCompany',
            jscript:'shapan/02group/newCompany',
            activity_mid:activity_mid,
            CompanyName:data
        })
    })
    });
    //获取活动信息
    router.get('/shapan/activitylist',function(req,res) {
            res.render('shapan/activityList', {
                layout: '',
                active: '',
                jscript: 'shapan/00activityList/activityList',

            })
        });
    //获取人员信息
    router.get('/shapan/group/companyInfo',function(req,res){
        var  activity_mid=req.param('activity_mid');
        var param={};
        param.activity_mid=activity_mid;
        Action.send(req,res,'/Group/groupNames',param,'GET',function(res,data) {

            var json = JSON.parse(data);

            var dataGroup = json.data;
            console.log('dataGroup:',dataGroup);

            Action.send(req, res, '/Role/roleNames', {}, 'POST', function (res, data) {
                var json = JSON.parse(data);
                console.log(json);
                var dataRole = json.data;

                res.render('shapan/02group/companyInfo', {
                    layout: 'keb2/layout-keb',
                    active: 'companyInfo',
                    jscript: 'shapan/02group/roleFenpei',
                    dataGroup: dataGroup,
                    dataRole:dataRole,
                    dataGroupedit: dataGroup,
                    dataRoleedit:dataRole,
                    activity_mid:activity_mid
                })
            });
        })
    })

    //参数设定
    router.get('/shapan/parameter/parameter',function(req,res){
        var  activity_mid=req.param('activity_mid');
        res.render('shapan/03parameter/parameter',{
            layout:'keb2/layout-keb',
            active:'',
            jscript:'shapan/03parameter/parameter',
            activity_mid:activity_mid
        })
    })

    //年度决策
    router.get('/shapan/decision/RDdecision',function(req,res){
        var  activity_mid=req.param('activity_mid');
        res.render('shapan/04decision/RDdecision',{
            layout:'keb2/layout-keb',
            active:'RDdecision',
            jscript:'shapan/04decision/RDdecision',
            activity_mid:activity_mid
        })
    });

    router.get('/shapan/decision/manageDecision',function(req,res){
        var  activity_mid=req.param('activity_mid');
        var param={};
        param.activity_mid=activity_mid;
        Action.send(req,res,'/Group/groupNames',param,'GET',function(res,data) {

            var json = JSON.parse(data);

            var dataGroup = json.data;

            res.render('shapan/04decision/manageDecision', {
                layout: 'keb2/layout-keb',
                active: 'manageDecision',
                jscript: 'shapan/04decision/manageDecision',
                dataGroup:dataGroup,
                activity_mid:activity_mid
            })
        })
    });

    router.get('/shapan/decision/marketecision',function(req,res){
        var  activity_mid=req.param('activity_mid');
        var param={};
        param.activity_mid=activity_mid;
        Action.send(req,res,'/Group/groupNames',param,'GET',function(res,data) {

            var json = JSON.parse(data);

            var dataGroup = json.data;

            res.render('shapan/04decision/marketecision', {
                layout: 'keb2/layout-keb',
                active: 'marketecision',
                jscript: 'shapan/04decision/marketecision',
                dataGroup: dataGroup,
                activity_mid:activity_mid
            })
        })
    });

    router.get('/shapan/decision/otherDecision',function(req,res){

        var  activity_mid=req.param('activity_mid');
        var param={};
        param.activity_mid=activity_mid;
        Action.send(req,res,'/Group/groupNames',param,'GET',function(res,data) {

            var json = JSON.parse(data);

            var dataGroup = json.data;

            res.render('shapan/04decision/otherDecision',{
                layout:'keb2/layout-keb',
                active:'otherDecision',
                jscript:'shapan/04decision/otherDecision',
                dataGroup:dataGroup,
                activity_mid:activity_mid
            })
        })
    });

    //研发排名
    router.get('/shapan/RDrank/RDrank',function(req,res){
        var  activity_mid=req.param('activity_mid');
        res.render('shapan/05RDrank/RDrank',{
            layout:'keb2/layout-keb',
            active:'',
            jscript:'shapan/05RDrank/RDrank',
            activity_mid:activity_mid
        })
    });

    //选单排名
    router.get('/shapan/topMenu/topMenu',function(req,res){
        var  activity_mid=req.param('activity_mid');
        res.render('shapan/06topMenu/topMenu',{
            layout:'keb2/layout-keb',
            active:'',
            jscript:'shapan/06topMenu/topMenu',
            activity_mid:activity_mid
        })
    });

    //招标投标
    router.get('/shapan/bidding/bidding',function(req,res){

        var  activity_mid=req.param('activity_mid');
        var param={};
        param.activity_mid=activity_mid;

        Action.send(req,res,'/Group/groupNames',param,'GET',function(res,data) {

            var json = JSON.parse(data);

            var dataGroup = json.data;

            res.render('shapan/07bidding/bidding', {
                layout: 'keb2/layout-keb',
                active: '',
                jscript: 'shapan/07bidding/bidding',
                dataGroup:dataGroup,
                activity_mid:activity_mid
            })
        });

    });

    //奖励等级

    //额外奖励
    router.get('/shapan/rewardRegist/extraBonus',function(req,res){

        var  activity_mid=req.param('activity_mid');

        var param={};

        param.activity_mid=activity_mid;
        //console.log(activity_mid);

        Action.send(req,res,'/Group/groupNames',param,'GET',function(res,data) {

            var json = JSON.parse(data);

            var dataGroup = json.data;

            console.log(dataGroup);

            Action.send(req,res,'/ExtraBonus/ExtraBonusShow',param,'GET',function(res,data) {

                var json = JSON.parse(data);

                var ExtraBonusData = json.data;

                res.render('shapan/08rewardRegist/extraBonus', {
                    layout: 'keb2/layout-keb',
                    active: 'extraBonus',
                    jscript: 'shapan/08rewardRegist/extraBonus',
                    dataGroup: dataGroup,
                    ExtraBonusData:ExtraBonusData,
                    activity_mid:activity_mid
                })
            })
        })
    });

    //团队作战能力
    router.get('/shapan/rewardRegist/teamCombatCapability',function(req,res){

        var  activity_mid=req.param('activity_mid');
        var param={};
        param.activity_mid=activity_mid;

        Action.send(req,res,'/Group/groupNames',param,'GET',function(res,data) {

            var json = JSON.parse(data);

            var dataGroup = json.data;

            res.render('shapan/08rewardRegist/teamCombatCapability',{
                layout:'keb2/layout-keb',
                active:'teamCombatCapability',
                jscript:'shapan/08rewardRegist/teamCombatCapability',
                dataGroup:dataGroup,
                activity_mid:activity_mid
            })
        });
    });

    //各类报表

    //生成报表
    router.get('/shapan/reportform/produce',function(req,res){
        var  activity_mid=req.param('activity_mid');
        res.render('shapan/09reportform/produce',{
            layout:'keb2/layout-keb',
            active:'produce',
            jscript:'shapan/09reportform/produce',
            activity_mid:activity_mid
        })
    });

    //资金盘点表
    router.get('/shapan/reportform/capital',function(req,res){

        var activity_mid=req.param("activity_mid");
        var params={
            year_id:1,
            activity_mid:activity_mid
        };
        Action.send(req,res,'/Capital/CapitaShow',params,'GET',function(res,data) {

            var json = JSON.parse(data);

            var Capital1 = json.data;

            var params2 = {
                year_id: 2,
                activity_mid: activity_mid
            };
            Action.send(req,res,'/Capital/CapitaShow',params2,'GET',function(res,data) {

                var json = JSON.parse(data);

                var Capital2 = json.data;

                var params3 = {
                    year_id: 3,
                    activity_mid: activity_mid
                };
                Action.send(req,res,'/Capital/CapitaShow',params3,'GET',function(res,data) {

                    var json = JSON.parse(data);

                    var Capital3 = json.data;

                    res.render('shapan/09reportform/capital', {
                        layout: 'keb2/layout-keb',
                        active: 'capital',
                        jscript: '',
                        Capital1: Capital1,
                        Capital2: Capital2,
                        Capital3: Capital3,
                        activity_mid: activity_mid
                    })
                })
            })
        })
    });

    //购产销能力表
    router.get('/shapan/reportform/purchaseAndSale',function(req,res){

        var activity_mid=req.param("activity_mid");
        var params={
            year_id:1,
            activity_mid:activity_mid
        };
        Action.send(req,res,'/Capital/productionShow',params,'GET',function(res,data) {

            var json = JSON.parse(data);

            var netProfit1 = json.data;

            var params2 = {
                year_id: 2,
                activity_mid: activity_mid
            };
            Action.send(req,res,'/Capital/productionShow',params2,'GET',function(res,data) {

                var json = JSON.parse(data);

                var netProfit2 = json.data;

                var params3 = {
                    year_id: 3,
                    activity_mid: activity_mid
                };
                Action.send(req,res,'/Capital/productionShow',params3,'GET',function(res,data) {

                    var json = JSON.parse(data);

                    var netProfit3 = json.data;

                    res.render('shapan/09reportform/purchaseAndSale',{
                        layout:'keb2/layout-keb',
                        active:'purchaseAndSale',
                        jscript:'',
                        netProfit1:netProfit1,
                        netProfit2:netProfit2,
                        netProfit3:netProfit3,
                        activity_mid: activity_mid
                    })
                })
            })
        })
    });

    //净利润表
    router.get('/shapan/reportform/netProfit',function(req,res){

        var activity_mid=req.param("activity_mid");
        var params={
            year_id:1,
            activity_mid:activity_mid
        };
        Action.send(req,res,'/Np/npShow',params,'GET',function(res,data) {

            var json = JSON.parse(data);

            var netProfit1 = json.data;

            var params2 = {
                year_id: 2,
                activity_mid: activity_mid
            };
            Action.send(req,res,'/Np/npShow',params2,'GET',function(res,data) {

                var json = JSON.parse(data);

                var netProfit2 = json.data;

                var params3 = {
                    year_id: 3,
                    activity_mid: activity_mid
                };
                Action.send(req,res,'/Np/npShow',params3,'GET',function(res,data) {

                    var json = JSON.parse(data);

                    var netProfit3 = json.data;

                    res.render('shapan/09reportform/netProfit',{
                        layout:'keb2/layout-keb',
                        active:'netProfit',
                        jscript:'',
                        netProfit1:netProfit1,
                        netProfit2:netProfit2,
                        netProfit3:netProfit3,
                        activity_mid: activity_mid
                    })
                })
            })
        })
    });

    //团队排名
    router.get('/shapan/reportform/teamRanking',function(req,res){

        var activity_mid=req.param("activity_mid");
        var params={
            year_id:1,
            activity_mid:activity_mid
        };
        Action.send(req,res,'/TeamRanking/TeamRankingShow',params,'GET',function(res,data) {

            var json = JSON.parse(data);

            var TeamRankingShow1 = json.data;
            var params2={
                year_id:2,
                activity_mid:activity_mid
            };
            Action.send(req,res,'/TeamRanking/TeamRankingShow',params2,'GET',function(res,data) {

                var json = JSON.parse(data);

                var TeamRankingShow2 = json.data;

                var params3={
                    year_id:3,
                    activity_mid:activity_mid
                };
                Action.send(req,res,'/TeamRanking/TeamRankingShow',params3,'GET',function(res,data) {

                    var json = JSON.parse(data);

                    var TeamRankingShow3 = json.data;

                    res.render('shapan/09reportform/teamRanking', {
                        layout: 'keb2/layout-keb',
                        active: 'teamRanking',
                        jscript: '',
                        TeamRankingShow1: TeamRankingShow1,
                        TeamRankingShow2: TeamRankingShow2,
                        TeamRankingShow3: TeamRankingShow3,
                        activity_mid: activity_mid
                    })
                })
            })
        })
    });

    //年度总结
    router.get('/shapan/summary/summary',function(req,res){

        var  activity_mid=req.param('activity_mid');
        var param={};
        param.activity_mid=activity_mid;

        Action.send(req,res,'/Group/groupNames',param,'GET',function(res,data) {

            var json = JSON.parse(data);

            var dataGroup = json.data;

            res.render('shapan/10summary/summary', {
                layout: 'keb2/layout-keb',
                active: '',
                jscript: 'shapan/10summary/summary',
                dataGroup:dataGroup,
                activity_mid: activity_mid
            })
        })
    });

    //生成现金回报
    router.get('/shapan/cashReturn/createcashReturn',function(req,res){
        var  activity_mid=req.param('activity_mid');
        res.render('shapan/11cashReturn/createcashReturn', {
            layout: 'keb2/layout-keb',
            active: 'createcash',
            jscript: 'shapan/11cashReturn/createcashReturn',
            activity_mid: activity_mid
        })
    });

    //现金回报展示
    router.get('/shapan/cashReturn/cashReturn',function(req,res){

        var  activity_mid=req.param('activity_mid');
        var param={};
        param.activity_mid=activity_mid;

        Action.send(req,res,'/Group/groupNames',param,'GET',function(res,data) {

            var json = JSON.parse(data);

            var dataGroup = json.data;

            res.render('shapan/11cashReturn/cashReturn', {
                layout: 'keb2/layout-keb',
                active: 'huibao',
                jscript: 'shapan/11cashReturn/cashReturn',
                dataGroup:dataGroup,
                activity_mid: activity_mid
            })
        })
    });

};
